﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DcsGauges.Gui.Rendering;
using Microsoft.Xna.Framework.Graphics;
using DcsGauges.DataStructures;
using DcsGauges.Shared.DataStructures;
using DcsGauges.Gui.Gauges.ValueConverters;
using DcsGauges.Gui.Gauges.Interfaces;
using DcsGauges.Gui.Gauges.Trigger;
using Microsoft.Xna.Framework;
using System.Diagnostics;

namespace DcsGauges.Gui.Gauges.Panels
{
    class TestingPanel : GuiRenderableBase, IMultiTriggerGauge
    {
        //public ThreeAnalogNumberGauge             gauge = null;
        //public TwoStateToggleSwitchGauge          gauge = null;
        private ElectricalPanel                     gauge = null;
        private OxygenPanel                         oxygen = null;

        public TestingPanel(GuiRenderableBase parent, GraphicsDevice device) : base(parent, URect.Full)
        {
            //this.gauge                  = new ThreeAnalogNumberGauge(URect.Full, device,
            //    new Tuple<DcsProperty, IGaugeValueConverter<float>>(DcsProperties.Unknown, new VoidValueConverter()), 
            //    new Tuple<DcsProperty, IGaugeValueConverter<float>>(DcsProperties.Unknown, new VoidValueConverter()), 
            //    new Tuple<DcsProperty, IGaugeValueConverter<float>>(DcsProperties.Unknown, new VoidValueConverter()));

            //this.gauge                  = new TwoStateToggleSwitchGauge(this, URect.Full,
            //    TextureManager.GetTexture("Textures/Gauges/Foregrounds/ToggleswitchUp"),
            //    TextureManager.GetTexture("Textures/Gauges/Foregrounds/ToggleswitchDown"),
            //    new StateConverter<TwoStateToggleSwitchGauge.SwitchStates>(
            //        (v) => {return v > 0.5 ? TwoStateToggleSwitchGauge.SwitchStates.On : TwoStateToggleSwitchGauge.SwitchStates.Off;}, 
            //        (s) => { return s == TwoStateToggleSwitchGauge.SwitchStates.On ? 1.0f : 0.0f; }), 
            //    DcsProperties.Unknown);

            this.gauge      = new ElectricalPanel(this, new URect(new ULoc(0.0f, 0.0f), new USize(1.0f, 0.6f)));
            this.oxygen     = new OxygenPanel(this, new URect(new ULoc(0.0f, 0.6f),     new USize(1.0f, 0.4f)));

            this.children.Add(gauge);
        }

        public override void Render(SpriteBatch spriteBatch, GraphicsDevice device, Rectangle parentRect, float globalZIndex)
        {
            this.gauge.Render(spriteBatch, device, parentRect, globalZIndex);
            this.oxygen.Render(spriteBatch, device, parentRect, globalZIndex);
        }

        public override void InjectMouseEvent(Input.Events.MouseEvent evt, GameTime gt)
        {
            base.InjectMouseEvent(evt, gt);
        }
    
        public DcsProperty[]  Properties
        {
	        get { return this.gauge.Properties.Concat(this.oxygen.Properties).ToArray(); }
        }

        public void  SetValue(DcsProperty property, float value)
        {
            if (this.gauge.Properties.Contains(property))
            {
                this.gauge.SetValue(property, value);
            }
            else if (this.oxygen.Properties.Contains(property))
            {
                this.oxygen.SetValue(property, value);
            }
            else
            {
                Debug.Assert(false, "Invalid property set in Testing Panel");
            }
        }

        public float  GetValue(DcsProperty property)
        {
 	        return 0.0f;
        }

        public event EventHandler<TriggerValueEventArgs>  TriggerEvent;
    }
}
